<?php

/**
 * Usuario form.
 *
 * @package    form
 * @subpackage Usuario
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class UsuarioForm extends BaseUsuarioForm
{
  protected function initialize()
  {
  	$this->labels = array
  	                (
  	                  'perfil_id'        => 'Perfil de Usuario',
  	                  'familia_id'       => 'Grupo Familiar',
  	                  'login'            => 'Usuario',
  	                  'password'         => 'Contraseña',
  	                  'confirm_password' => 'Verifica tu Contraseña',
  	                  'email'            => 'E-mail',
  	                  'estado'           => 'Estado'
  	                );
  }
  public function configure()
  {
  	$this->setWidgets(array
  	(
  	  'perfil_id'        => new sfWidgetFormDoctrineSelect
                             (
                               array
                               (
                                 'model'     => 'Perfil', 
                                 'add_empty' => '---Seleccionar---', 
                                 'order_by'  => array('Nombre', 'asc')
                               )
                             ),
  	  'familia_id'      => new sfWidgetFormDoctrineSelect
                             (
                               array
                               (
                                 'model'     => 'Familia', 
                                 'add_empty' => '---Seleccionar---', 
                                 'order_by'  => array('Nombre', 'asc')
                               )
                             ),
      'login'            => new sfWidgetFormInput(array(), array('size' => 20)),
      'password'         => new sfWidgetFormInputPassword(array(), array('size' => '10')),                             
      'confirm_password' => new sfWidgetFormInputPassword(array(), array('size' => '10')),
      'email'            => new sfWidgetFormInput(array(), array('size' => 20)),
      'estado'           => new sfWidgetFormSelect(array('choices' => $this->getObject()->getTable()->getEstado())),
  	));
  	
  	$this->types = array
  	(
  	  'id'               => '=',
      'perfil_id'        => array('combo', array()),
      'familia_id'       => array('combo', array()),
      'login'            => 'name',
      'password'         => 'password',
  	  'confirm_password' => 'password',
      'email'            => 'name',
      'estado'           => array('combo', array('choices' => array_keys($this->getObject()->getTable()->getEstado()))),
      'last_access_at'   => '-',
      'slug'             => '-',
      'created_at'       => '-',
      'updated_at'       => '-',
  	);
  	
  	$this->validatorSchema['confirm_password'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
    
    $this->validatorSchema->setPostValidator
    (
      new sfValidatorAnd
      (
        array
        (
          new sfValidatorDoctrineUnique(array('model' => $this->getModelName(), 'column' => array('login') , 'throw_global_error' => false)),
          new sfValidatorDoctrineUnique(array('model' => $this->getModelName(), 'column' => array('email') , 'throw_global_error' => false)),
          new sfValidatorSchemaCompare
          (
            'password', '==', 'confirm_password',
             array('throw_global_error' => false),
             array('invalid'            => 'El \'%password%\' y el \'%confirm_password%\' deben ser iguales.')
          )
        )
      )
    );
  }
  
  public function postConfigure()
  {
  //  $this->addPacienteForm();
  }
/*  
  public function addPacienteForm()
  {
    if ($this->isNew())
    {
      $paciente = new Paciente();
      $paciente->setParentesco(Doctrine::getTable('Parentesco')->findOneByNombre('Yo'));
      $paciente->setUsuario($this->getObject());
      $paciente->setEstado(1);
      $paciente->setTipoPaciente('N');
    }
    else
    {
      if (!$paciente = Doctrine::getTable('Paciente')->findOneByUsuarioId($this->object->getId()))
      {
        $paciente = new Paciente();
        $paciente->setUsuario($this->getObject());
      }
    }
    
    $pacienteForm = new PacienteForm($paciente);
    $pacienteForm->getWidgetSchema()->setNameFormat('usuario[paciente][%s]');
    
    $pacienteForm->buildLabels();
    $this->embedForm('paciente', $pacienteForm);
    //$this->widgetSchema->setLabel('image', 'Image')
  }*/

}